{extend name='common/_container'}
{block name="content"}
<div class="ibox float-e-margins">
	<div class="ibox-content">
		<div class="form-horizontal" id="CodeInfoForm">
			<div class="row">
				<div class="col-sm-12">
				<!-- form start -->
					<div class="form-group">
						<label class="col-sm-2 control-label">标题：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="title" value="" name="title" class="form-control" placeholder="请输入标题">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">版本：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="edition" value="" name="edition" class="form-control" placeholder="请输入版本">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">简短描述：</label>
						<div class="col-sm-9">
							<textarea id="describes" name="describes"  class="form-control" placeholder="请输入简短描述"></textarea>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">缩略图：</label>
						<div class="col-sm-6">
							<input type="text" autocomplete="off" id="img" value="" {if condition="config('my.img_show_status') eq true"}onmousemove="showBigPic(this.value)" onmouseout="closeimg()"{/if} name="img" class="form-control" placeholder="请输入缩略图">
							<span class="help-block m-b-none img_process"></span>
						</div>
						<div class="col-sm-2" style="position:relative; right:30px;">
							<span id="img_upload"></span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">价格设置：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="price" value="" name="price" class="form-control" placeholder="请输入价格设置">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">原价增加金额：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="original_price" value="" name="original_price" class="form-control" placeholder="请输入原价增加金额">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">参与人数（虚）：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="number_void" value="0" name="number_void" class="form-control" placeholder="请输入参与人数（虚）">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">是否免费：</label>
						<div class="col-sm-9">
							<?php if(!isset($info['free'])){ $info['free'] = ''; }; ?>
							<select lay-ignore name="free" class="form-control" id="free">
								<option value="">请选择</option>
								<option value="1" {if condition="$info.free eq '1'"}selected{/if}>付费测试</option>
								<option value="2" {if condition="$info.free eq '2'"}selected{/if}>免费测试</option>
								<option value="3" {if condition="$info.free eq '3'"}selected{/if}>关注测试</option>
							</select>
						</div>
					</div>
					<div class="form-group layui-form">
						<label class="col-sm-2 control-label">是否显示：</label>
						<div class="col-sm-9">
							<?php if(!isset($info['extension'])){ $info['extension'] = 0; }; ?>
							<input name="extension" value="1" type="radio" {if condition="$info.extension eq '1'"}checked{/if} title="开启">
							<input name="extension" value="0" type="radio" {if condition="$info.extension eq '0'"}checked{/if} title="关闭">
						</div>
					</div>
					<div class="form-group layui-form">
						<label class="col-sm-2 control-label">是否推荐：</label>
						<div class="col-sm-9">
							<?php if(!isset($info['is_recommend'])){ $info['is_recommend'] = 0; }; ?>
							<input name="is_recommend" value="1" type="radio" {if condition="$info.is_recommend eq '1'"}checked{/if} title="是">
							<input name="is_recommend" value="0" type="radio" {if condition="$info.is_recommend eq '0'"}checked{/if} title="否">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">内容：</label>
						<div class="col-sm-9">
							<script id="content" type="text/plain" name="content" style="width:100%;height:300px;"></script>
							<script type="text/javascript">
								var ue = UE.getEditor('content',{serverUrl : '{:url("admin/Upload/uploadUeditor")}'});
								scaleEnabled:true
							</script>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">推广二维码底图：</label>
						<div class="col-sm-6">
							<input type="text" autocomplete="off" id="qrcode" value="" {if condition="config('my.img_show_status') eq true"}onmousemove="showBigPic(this.value)" onmouseout="closeimg()"{/if} name="qrcode" class="form-control" placeholder="请输入推广二维码底图">
							<span class="help-block m-b-none qrcode_process"></span>
						</div>
						<div class="col-sm-2" style="position:relative; right:30px;">
							<span id="qrcode_upload"></span>
						</div>
					</div>
				<!-- form end -->
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="row btn-group-m-t">
				<div class="col-sm-9 col-sm-offset-1">
					<button type="button" class="btn btn-primary" onclick="CodeInfoDlg.add()" id="ensure">
						<i class="fa fa-check"></i>&nbsp;确认提交
					</button>
					<button type="button" class="btn btn-danger" onclick="CodeInfoDlg.close()" id="cancel">
						<i class="fa fa-eraser"></i>&nbsp;取消
					</button>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="__PUBLIC__/static/js/upload.js" charset="utf-8"></script>
<script src="__PUBLIC__/static/js/plugins/layui/layui.js" charset="utf-8"></script>
<script>
layui.use(['form'],function(){});
uploader('img_upload','img','image',false,'','{:getUploadServerUrl()}');
uploader('qrcode_upload','qrcode','image',false,'','{:getUploadServerUrl()}');
var CodeInfoDlg = {
	CodeInfoData: {},
	validateFields: {
		title: {
			validators: {
				notEmpty: {
					message: '标题不能为空'
	 			},
	 		}
	 	},
		edition: {
			validators: {
				notEmpty: {
					message: '版本不能为空'
	 			},
	 		}
	 	},
		img: {
			validators: {
				notEmpty: {
					message: '缩略图不能为空'
	 			},
	 		}
	 	},
		price: {
			validators: {
				regexp: {
					regexp: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
					message: ''
	 			},
	 		}
	 	},
	 }
}

CodeInfoDlg.collectData = function () {
	this.set('mbti_id').set('title').set('edition').set('describes').set('img').set('price').set('original_price').set('number_void').set('free').set('qrcode');
};

CodeInfoDlg.add = function () {
	 this.clearData();
	 this.collectData();
	 if (!this.validate()) {
	 	return;
	 }
	 var extension = $("input[name = 'extension']:checked").val();
	 var is_recommend = $("input[name = 'is_recommend']:checked").val();
	 var content = UE.getEditor('content').getContent();
	 var ajax = new $ax(Feng.ctxPath + "/Mbti.Lists/add", function (data) {
	 	if ('00' === data.status) {
	 		Feng.success(data.msg,1000);
	 		window.parent.CodeGoods.table.refresh();
	 		CodeInfoDlg.close();
	 	} else {
	 		Feng.error(data.msg + "！",1000);
		 }
	 })
	 ajax.set('extension',extension);
	 ajax.set('is_recommend',is_recommend);
	 ajax.set('content',content);
	 ajax.set(this.CodeInfoData);
	 ajax.start();
};


</script>
<script src="__PUBLIC__/static/js/base.js" charset="utf-8"></script>
{/block}
